package com.tanhua.server.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;


import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.service.RecommendUserService;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

@Service
public class RecommendUserServiceImpl implements RecommendUserService {
    //如果出现空指针异常,是因为RecommendUserApi所在的服务没有启动起来,需要先启动my-tanhua-dubbo-service服务
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;


    @Override
    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(id);
        if (null == recommendUser) {
            return null;
        }

        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分值,就是score向下取整
        double score = Math.floor(recommendUser.getScore());//取整,98.2 -> 98
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    @Override
    public PageInfo<RecommendUser> queryRecommendUserList(Long userId, Integer pageNum, Integer pageSize) {
        return recommendUserApi.queryPageInfo(userId, pageNum, pageSize);
    }
}
